package cn.hx.mall.sell.service.impl;

import cn.hx.mall.sell.dao.SmsFlashPromotionSessionDao;
import cn.hx.mall.sell.entity.SmsFlashPromotionSession;
import cn.hx.mall.sell.service.SmsFlashPromotionSessionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 限时购场次表(SmsFlashPromotionSession)表服务实现类
 *
 * @author makejava
 * @since 2022-11-02 16:10:30
 */
@Service("smsFlashPromotionSessionService")
public class SmsFlashPromotionSessionServiceImpl implements SmsFlashPromotionSessionService {
    @Resource
    private SmsFlashPromotionSessionDao smsFlashPromotionSessionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SmsFlashPromotionSession queryById(Long id) {
        return this.smsFlashPromotionSessionDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<SmsFlashPromotionSession> queryAllByLimit(int offset, int limit) {
        return this.smsFlashPromotionSessionDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param smsFlashPromotionSession 实例对象
     * @return 实例对象
     */
    @Override
    public SmsFlashPromotionSession insert(SmsFlashPromotionSession smsFlashPromotionSession) {
        smsFlashPromotionSession.setCreateTime(new Date());
        this.smsFlashPromotionSessionDao.insert(smsFlashPromotionSession);
        return smsFlashPromotionSession;
    }

    /**
     * 修改数据
     *
     * @param smsFlashPromotionSession 实例对象
     * @return 实例对象
     */
    @Override
    public SmsFlashPromotionSession update(SmsFlashPromotionSession smsFlashPromotionSession) {
        this.smsFlashPromotionSessionDao.update(smsFlashPromotionSession);
        return this.queryById(smsFlashPromotionSession.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.smsFlashPromotionSessionDao.deleteById(id) > 0;
    }

    @Override
    public List<SmsFlashPromotionSession> queryAll(SmsFlashPromotionSession smsFlashPromotionSession) {
        return smsFlashPromotionSessionDao.queryAll(smsFlashPromotionSession);
    }

    @Override
    public List<SmsFlashPromotionSession> queryByPromotionId(Long flashPromotionId) {
        return smsFlashPromotionSessionDao.queryByFlashPromotionId(flashPromotionId);
    }

    @Override
    public int queryProductCount(Long id, Long flashPromotionId) {
        return smsFlashPromotionSessionDao.queryProductCount(id, flashPromotionId);
    }
}